package com.intellagric.controller.module.cms_content;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.cms.ContentVo;
import com.intellagric.pojo.CmsCategoryContent;
import com.intellagric.service.module.cms_content.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Auther: zhy
 * @Date: 2018/10/19
 * @Description: 前台网站内容管理
 */
@Controller
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 添加内容信息
     * @Param content
     * @return ResponseMessage
     */
    @RequestMapping("/content/add")
    @ResponseBody
    public ResponseMessage add(CmsCategoryContent content) {
        content.setId(UUID.randomUUID().toString().replaceAll("-",""));
        content.setCreateDate(new Date());
        content.setUpdateDate(new Date());
        return contentService.addContent(content);
    }


    /**
     * 删除内容信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/content/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return contentService.deleteContent(id);
    }

    /**
     * 修改信息
     * @Param content
     * @return ResponseMessage
     */
    @RequestMapping("/content/edit")
    @ResponseBody
    public ResponseMessage edit(CmsCategoryContent content) {
        content.setUpdateDate(new Date());
        return contentService.editContent(content);
    }

    /**
     * 查询内容信息
     * @Param id
     * @return Content
     */
    @RequestMapping("/content/detail/{id}")
    @ResponseBody
    public CmsCategoryContent get(@PathVariable String id) {
        return contentService.queryContentById(id);
    }

    /**
     * 查询内容信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/content/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return contentService.queryContentList();
    }

    /**
     * 查询内容信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/content/page")
    @ResponseBody
    public LayuiDataGridResult getPageList(int page,int limit) {
        return contentService.queryContentPageList(page,limit);
    }

    /**
     * 通过ContentVo类查询内容信息列表
     * @Param contentVo
     * @return LayuiDataGridResult
     */
    @RequestMapping("/content/query")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,ContentVo contentVo) {
        return contentService.queryContentByVo(page, limit, contentVo);
    }

}
